﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Gencode.Gengui.Display
{
    [ToolboxItem(false)]
	public partial class DisplayableViewControler : GUControl
	{
		/// <summary>
		/// Is raised when a button is clicked
		/// </summary>
		public event EventHandler InternalSizeChange;

		public DisplayableViewControler()
		{
			InitializeComponent();
		}

		DisplayableView partnerView;
		public DisplayableView PartnerView
		{
			get
			{
				return partnerView;
			}
			set
			{
				partnerView = value;
			}
		}

		string m_text = string.Empty;
		/// <summary>
		///  The text to display inside the control.
		/// </summary>
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public override string Text
		{
			get
			{
				return (m_text);
			}
			set
			{
				m_text = value;
				if (HasHeader && Header != null)
					Header.Text = m_text;
			}
		}

		bool _hasHeader = true;
		/// <summary>
		/// display a header control?.
		/// </summary>
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool HasHeader
		{
			get
			{
				return (_hasHeader);
			}
			set
			{
				_hasHeader = value;
			}
		}

		bool _isStatic = true;
		/// <summary>
		///  static controls wil not be collapsed.
		/// </summary>
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public bool IsStatic
		{
			get
			{
				return (_isStatic);
			}
			set
			{
				_isStatic = value;
			}
		}

		Image _image;
		/// <summary>
		/// the image to be displayed in the header
		/// </summary>
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public Image Image
		{
			get
			{
				return (_image);
			}
			set
			{
				_image = value;
				if (HasHeader && Header != null)
					Header.Image = _image;
			}
		}

		ViewSelectionHeader _header;
		// The text to display inside the control.
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		public ViewSelectionHeader Header
		{
			get
			{
				return (_header);
			}
			set
			{
				if (value != null)
				{
					_header = value;
					if (Image != null)
						_header.Image = Image;
					_header.Text = Text;
					_header.PartnerView = this;
					_header.Width = this.Width;
				}
			}
		}

		private void DisplayableViewControler_SizeChanged(object sender, EventArgs e)
		{
			if (Header != null && this.Width > 0)
				Header.Width = this.Width;
		}

		/// <summary>
		/// Empty implementation.
		/// Has to be overriden if wanted to use!
		/// </summary>
		/// <param name="maxHeight"></param>
		public virtual int CalculateHeight(int maxHeight)
		{
			return maxHeight;
		}

		protected void CallForSizeChange()
		{
			if (InternalSizeChange != null)
				InternalSizeChange(this, new EventArgs());
		}
	}
}
